const host = "https://smallpro.zhiyoubao.com/"

const wxRequest = (params, url) => {
  wx.showToast({
    title: '加载中',
    icon: 'loading'
  })
  console.log(params);
  wx.request({
    url: url,
    method: params.method || 'POST',
    data: params.data || {},
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    success: (res) => {
      params.success && params.success(res)
      wx.hideToast()
    },
    fail: (res) => {
      params.fail && params.fail(res)
      console.log(res)
    },
    complete: (res) => {
      params.complete && params.complete(res)
    }
  })
}

// Index
const getTicketList = (params) => wxRequest(params, host + 'smallpro/ticket/scenicList.htm')

// Detail
const getScenicDetail = (params) => wxRequest(params, host + 'smallpro/ticket/scenicTicket.htm')

// Order
const getOrderInfo = (params) => wxRequest(params, host + 'smallpro/ticket/buyTicket.htm')
const getDayPrice = (params) => wxRequest(params, host + 'smallpro/ticket/calendarData.htm')
const goToPaying = (params) => wxRequest(params, host + 'smallpro/torder/saveTicketOrder.htm')
// Pay
const getPayInfo = (params) => wxRequest(params, host +'smallpro/torder/toPayOrder.htm')
const toWxPay = (params) => wxRequest(params, host +'smallpro/wxpay/wxPrePay.htm')

//myOrder
const getOrderList = (params) => wxRequest(params, host +'smallpro/order/allOrderGird.htm')
const cancelOrder = (params) => wxRequest(params, host + 'smallpro/order/cancleOrder.htm')
const refundOrder = (params) => wxRequest(params, host + 'smallpro/refund/refundOrder.htm')

//orderDetial
const getOrderDetail = (params) => wxRequest(params, host +'smallpro/order/orderDetail.htm')

module.exports = {
  getTicketList,
  getScenicDetail,
  getOrderInfo,
  getDayPrice,
  goToPaying,
  getPayInfo,
  toWxPay,
  getOrderList,
  cancelOrder,
  refundOrder,
  getOrderDetail
}
